import normalizeKeys from './util/normalizeKeys';

/**
 * 自定义response类
 * @class Response
 * @memberOf kryfe-lib.FetchRequest
 * @inner
 */
export default class Response {
  [x: string]: any;
  static isSuccess(responseCode) {
    return responseCode == "1";
  }

  static parseHeaders(res) {
    return {
      responseCode: res.ret,
      responseMessage: res.msg
    };
  }

  static parseBody(res) {
    return res.returns;
  }

  static resetStatic(methods) {
    Object.keys(methods).forEach(key => (Response[key] = methods[key]));
  }

  constructor(res) {
    this.headers = Response.parseHeaders(res);
    this.body = Response.parseBody(res);
    this.code = this.headers.responseCode;
    this.message = this.headers.responseMessage;
    this.success = Response.isSuccess(this.code);
  }
}
